package com.hq.fxh.Utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

import com.hq.fxh.No3_TuiGuang.MyMoBan.Model.ShareInfo;
import com.hq.fxh.R;

import java.util.HashMap;

import cn.jiguang.share.android.api.JShareInterface;
import cn.jiguang.share.android.api.PlatActionListener;
import cn.jiguang.share.android.api.Platform;
import cn.jiguang.share.android.api.ShareParams;
import cn.jiguang.share.android.utils.Logger;
import cn.jiguang.share.qqmodel.QQ;
import cn.jiguang.share.qqmodel.QZone;
import cn.jiguang.share.wechat.Wechat;
import cn.jiguang.share.wechat.WechatMoments;
import cn.jiguang.share.weibo.SinaWeibo;
import cn.jiguang.share.weibo.SinaWeiboMessage;

import static com.hq.fxh.imageLoader.video.VideoPicker.TAG;

/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/9/12
 * @Email xlwenhao1858@sina.com
 */


public class ShareUtils {

    public static void shareWeiXin(ShareInfo shareInfo) {
        //这里以分享链接为例
        ShareParams shareParams = new ShareParams();
        shareParams.setShareType(Platform.SHARE_WEBPAGE);
        shareParams.setTitle(shareInfo.getTitle());
        shareParams.setText(shareInfo.getText());
        shareParams.setShareType(Platform.SHARE_WEBPAGE);
        shareParams.setUrl(shareInfo.getUrl());
        shareParams.setImageUrl(shareInfo.getImgUrl());
        JShareInterface.share(Wechat.Name, shareParams, mShareListener);
    }

    public static void shareWechatMoments(ShareInfo shareInfo) {

        //这里以分享链接为例
        ShareParams shareParams = new ShareParams();
        shareParams.setShareType(Platform.SHARE_WEBPAGE);
        shareParams.setTitle(shareInfo.getTitle());
        shareParams.setText(shareInfo.getText());
        shareParams.setShareType(Platform.SHARE_WEBPAGE);
        shareParams.setUrl(shareInfo.getUrl());
        shareParams.setImageUrl(shareInfo.getImgUrl());
        JShareInterface.share(WechatMoments.Name, shareParams, mShareListener);
    }

    public static void shareQZone(ShareInfo shareInfo) {

        //这里以分享链接为例
        ShareParams shareParams = new ShareParams();
        shareParams.setShareType(Platform.SHARE_WEBPAGE);
        shareParams.setTitle(shareInfo.getTitle());
        shareParams.setText(shareInfo.getText());
        shareParams.setUrl(shareInfo.getUrl());
        shareParams.setImageUrl(shareInfo.getImgUrl());
        JShareInterface.share(QZone.Name, shareParams, mShareListener);
    }

    public static void shareQQ(ShareInfo shareInfo) {

        //这里以分享链接为例
        ShareParams shareParams = new ShareParams();
        shareParams.setShareType(Platform.SHARE_WEBPAGE);
        shareParams.setTitle(shareInfo.getTitle());
        shareParams.setText(shareInfo.getText());
        shareParams.setUrl(shareInfo.getUrl());
        shareParams.setImageUrl(shareInfo.getImgUrl());
        JShareInterface.share(QQ.Name, shareParams, mShareListener);
    }

    public static void shareSinaWeibo(Context context,ShareInfo shareInfo, Bitmap bitmap) {

        ShareParams shareParams = new ShareParams();
        shareParams.setShareType(Platform.SHARE_WEBPAGE);
        shareParams.setText(shareInfo.getTitle());

        if (bitmap == null) {
            bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ldd_logo);

        }
        shareParams.setImageData(bitmap);
        shareParams.setUrl(shareInfo.getUrl());


        JShareInterface.share(SinaWeibo.Name, shareParams, mShareListener);
    }

    public static void shareSinaWeiboMessage(ShareInfo shareInfo) {

        //这里以分享链接为例
        ShareParams shareParams = new ShareParams();
        shareParams.setShareType(Platform.SHARE_WEBPAGE);
        shareParams.setTitle(shareInfo.getTitle());
        shareParams.setText(shareInfo.getText());
        shareParams.setUrl(shareInfo.getUrl());
        shareParams.setImageUrl(shareInfo.getImgUrl());
        JShareInterface.share(SinaWeiboMessage.Name, shareParams, mShareListener);
    }

    public static void share(Activity context, ShareInfo shareInfo) {
        String pacName = "cn.wxb.www.hq";
        Intent intent = context.getPackageManager().getLaunchIntentForPackage(pacName);
        Bundle pBundle = new Bundle();
//                if (TextUtils.isEmpty(shareInfo.getImgUrl())) {
//                    shareInfo.setImgUrl("http://resource.ledianduo.com/images/logo.png");
//                }
        pBundle.putString("imgUrl", shareInfo.getImgUrl());
        pBundle.putInt("way", 2);
        pBundle.putString("url", shareInfo.getUrl());
        pBundle.putString("text", shareInfo.getText());
        pBundle.putString("title", shareInfo.getTitle());
        intent.putExtra("param", pBundle);
        context.startActivityForResult(intent, 0);
    }

    public static void toolShareWechat(Activity context, ShareInfo shareInfo) {
        String pacName = "cn.wxb.www.hq";
        Intent intent = context.getPackageManager().getLaunchIntentForPackage(pacName);

        Bundle pBundle = new Bundle();
        pBundle.putString("imgUrl", shareInfo.getImgUrl());
        pBundle.putInt("way", 1);
        pBundle.putString("url", shareInfo.getUrl());
        pBundle.putString("text", shareInfo.getText());
        pBundle.putString("title", shareInfo.getTitle());
        intent.putExtra("param", pBundle);
        context.startActivityForResult(intent, 0);
    }


    private static PlatActionListener mShareListener = new PlatActionListener() {
        @Override
        public void onComplete(Platform platform, int action, HashMap<String, Object> data) {

        }

        @Override
        public void onError(Platform platform, int action, int errorCode, Throwable error) {
            Logger.e(TAG, "error:" + errorCode + ",msg:" + error);

        }

        @Override
        public void onCancel(Platform platform, int action) {

        }
    };


}
